package com.example.xuegengwang.xuegengwang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;
import com.example.xuegengwang.xuegengwang.bean.MainIndexBean;

import java.util.List;

import common.BaseActivity;
import view.MyImageLoader;


/**
 * Created by Administrator on 2017/5/15.
 * 首页菜单适配器
 */

public class MainPageMenuAdapter extends BaseAdapter {
    private Context context;
    private List<MainIndexBean.MenuBean> arrayList;

    public MainPageMenuAdapter(Context context, List<MainIndexBean.MenuBean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyHolder myHolder ;
        if(convertView == null){
            myHolder = new MyHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.main_page_menu_item,null);
            myHolder.imageView = (ImageView) convertView.findViewById(R.id.main_page_menu_item_ima);
            myHolder.textView = (TextView) convertView.findViewById(R.id.main_page_menu_item_tv);
            convertView.setTag(myHolder);
        }else{
            myHolder = (MyHolder) convertView.getTag();
        }
        MyImageLoader.showImage(arrayList.get(position).getImage(),myHolder.imageView);
        myHolder.textView.setText(arrayList.get(position).getTitle());
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((BaseActivity)context).drumpActivity(arrayList.get(position).getLink());
            }
        });
        return convertView;
    }

    class MyHolder{
        ImageView imageView;
        TextView textView;
    }
}
